<template>
	<view>
		<button @tap="login">获取code</button>
	</view>
</template>

<script>
	import api from '../../utils/request.js'
	export default {
		data() {
			return {

			};
		},
		methods: {
			login() {
				let appid, secret, nickName, avatarUrl, code;
				uni.login({
					provider: 'weixin',
					success: (res) => {
						code = res.code //开发者获取到的code
						// 获取用户信息
						uni.getUserInfo({
							provider: 'weixin',
							success: (res) => {
								uni.setStorageSync('info', res.userInfo)
								// console.log(res);
								appid = 'wx694ee9921d32f828' //开发者的小程序appid
								secret = '0628bb21197c25b1ec14c40a670aae89' //开发者的小程序密钥
								nickName = res.userInfo.avatarUrl //用户昵称
								avatarUrl = res.userInfo.nickName //用户头像
								uni.request({
									url: 'https://meituan.thexxdd.cn/api/wx_login',
									method: 'post',
									data: {
										appid,
										secret,
										nickName,
										avatarUrl,
										code
									},
									success: (res) => {
										uni.setStorageSync('token', res.data.data
											.user_Token)
										uni.switchTab({
											url:'/pages/myuser/myuser'
										})
									}
								})
							}
						});
					}
				});
			}
		}
	}
</script>

<style lang="scss">

</style>
